package com.example.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys.entity.Dept;
import com.example.sys.mapper.DeptMapper;
import com.example.sys.service.DeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sys.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author anan
 * @since 2019-06-20
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public IPage<Dept> selectPage(DeptVo deptVo) {
        IPage<Dept> iPage = new Page<>(deptVo.getPage(),deptVo.getLimit());
        QueryWrapper<Dept> wrapper = new QueryWrapper<>();
        if (deptVo.getParentId()>=0)
            wrapper.eq("parent_id", deptVo.getParentId());
        if (!StrUtil.hasEmpty(deptVo.getDeptName()))
            wrapper.like("dept_name", deptVo.getDeptName());

        return deptMapper.selectPage(iPage, wrapper);
    }
}
